<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\CommissionWithdraw
 *
 * @property int $id
 * @property int $uid
 * @property int $card_id
 * @property float $amount
 * @property string $message
 * @property int $status
 * @property int $created_at
 * @property int $updated_at
 * @property-read \App\Models\BankCards $card
 * @property-read \App\Models\User $user
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CommissionWithdraw whereAmount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CommissionWithdraw whereCardId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CommissionWithdraw whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CommissionWithdraw whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CommissionWithdraw whereMessage($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CommissionWithdraw whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CommissionWithdraw whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CommissionWithdraw whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class CommissionWithdraw extends Model
{
    protected $table = 'commission_withdraw';
    protected $primaryKey = 'id';
    protected $guarded = ['id'];

    public $timestamps = false;

    public static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub
        static::creating(function ($model){
            if (!$model->created_at) $model->created_at = time();
        });

        static::updating(function ($model){
            if (!$model->updated_at) $model->updated_at = time();
        });
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'uid', 'uid');
    }

    public function card()
    {
        return $this->hasOne(BankCards::class, 'id', 'card_id');
    }
}
